$:.unshift(File.expand_path(File.dirname(__FILE__)+"/../lib"))
$:.unshift(File.expand_path(File.dirname(__FILE__)+"/../ext"))

require "test/unit"
begin
    require 'statsample'
    HAS_SS=true
rescue
    HAS_SS=false
end

if(HAS_GSL.nil?)
begin
    require 'rbgsl'
    HAS_GSL=true
rescue
    HAS_GSL=false
end
end

require "alglib"
require 'matrix'
class TestAlglibCorrelation < Test::Unit::TestCase
  def test_correlation
      a=[1,2,3,6,7,9,0,10]
      b=[2,5,  7,8,4,8, 0,  5]

      if(HAS_GSL)
          a_gsl=GSL::Vector.alloc(a)
          b_gsl=GSL::Vector.alloc(b)
          corr_expected=GSL::Stats::correlation(a_gsl, b_gsl)
          corr_alglib=Alglib.pearson_correlation(a,b)
          assert_equal(corr_expected,corr_alglib)
      end
      if(HAS_SS)
          va=a.to_vector(:scale)
          vb=b.to_vector(:scale)
          corr_expected=Statsample::Bivariate::spearman(va, vb)
          corr_alglib=Alglib.spearman_correlation(a,b)
          assert_in_delta(corr_expected,corr_alglib,0.001)
      end
  end

end
